{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a4f215d2",
   "metadata": {},
   "source": [
    "2022/10/24 week10"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90d01d53",
   "metadata": {},
   "source": [
    "# 本周学习目标\n",
    ">1. while循环\n",
    ">2. 购物车实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b85ad9d",
   "metadata": {},
   "source": [
    "# 1. while循环\n",
    "### 回顾：for循环 ： for + range() 可以指定循环的次数---> 关于网页URL队列的抓取实践\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "964d5e60",
   "metadata": {},
   "source": [
    "## 1. while循环\n",
    "\n",
    "* 回顾：for 循环   ：for + range() 可以指定循环的次数--->关于网页URL队列的抓取实践\n",
    "* while循环：当某种条件成立时，停止循环\n",
    "* while True : 无限循环/死循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "525b7850",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙... 0\n",
      "你是风儿我是沙... 1\n",
      "你是风儿我是沙... 2\n",
      "你是风儿我是沙... 3\n",
      "你是风儿我是沙... 4\n",
      "你是风儿我是沙... 5\n",
      "你是风儿我是沙... 6\n",
      "你是风儿我是沙... 7\n",
      "你是风儿我是沙... 8\n",
      "你是风儿我是沙... 9\n"
     ]
    }
   ],
   "source": [
    "# 1. 指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙...\",count)\n",
    "    count = count+1\n",
    "    if count == 10:\n",
    "        break # break 终止循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "283cc358",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登陆成功~欢迎+user01\n"
     ]
    }
   ],
   "source": [
    "# 2. while True循环，可以让用户重复输入\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "count = 0 # 计数器\n",
    "\n",
    "while True:\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎+user01\")\n",
    "        break # 终止循环\n",
    "    # 二：账号不存在或密码不正确，用户可以输入三次，三次后1小时再来尝试\n",
    "    else:\n",
    "        if count<2:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+str(2-count)+\"次尝试机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时后再来尝试\")\n",
    "            break\n",
    "    count = count+1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9ba790f",
   "metadata": {},
   "source": [
    "# 2. 购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28d232dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. 运行程序\n",
    "\n",
    "product_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"芒果奶盖\",10],\n",
    "    [\"芋泥啵啵奶茶\",12],\n",
    "    [\"蜜雪柠檬茶\",8],\n",
    "]\n",
    "Alipay = input(\"请输入余额：\")\n",
    "print(\"--------商品列表--------\")\n",
    "print(product_list[0][0],str(product_list[0][1])+\"元\")\n",
    "print(product_list[0][0],str(product_list[1][1])+\"元\")\n",
    "print(product_list[0][0],str(product_list[2][1])+\"元\")\n",
    "print(product_list[0][0],str(product_list[3][1])+\"元\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12fc5243",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50fced3e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
